package com.qfedu.provider.controller;

import com.qfedu.config.SystemConfig;
import com.qfedu.params.UserDetailUpdateParam;
import com.qfedu.provider.service.DbUserDetailService;
import com.qfedu.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Administrator
 * @date 2024/11/23 下午12:28
 */
@RestController
@RequestMapping("server/detail")
@Tag(name = "用户详情管理")
@RequiredArgsConstructor
public class UserDetailController {
    private final DbUserDetailService dbUserDetailService;

    /**
     * 根据用户详情的id删除用户的数据
     * @param userId 用户的id
     * @return 处理结果
     */
    @Operation(summary = "删除用户详情")
    @DeleteMapping("delete")
    public R delete(Integer userId,HttpServletRequest request) {

        return dbUserDetailService.lgDelUser(userId,request.getHeader(SystemConfig.IP));
    }

    /**
     * 修改用户的详细信息
     * @param updateParam 修改用户的参数
     * @return 处理结果
     */
    @Operation(summary = "修改用户详情++")
    @PutMapping("update")
    public R update(@RequestBody UserDetailUpdateParam updateParam, HttpServletRequest request) {
        return dbUserDetailService.updateUserDetail(updateParam,request.getHeader(SystemConfig.IP));
    }

    /**
     * 用户的id,查询用户的详细信息
     * @param userId 用户的id
     * @param request 请求
     * @return 查询用户的详情
     */
    @Operation(summary = "根据id查询用户详情")
    @GetMapping("findById")
    public R findById(@RequestParam(value = "userId") Integer userId, HttpServletRequest request) {
        String token = request.getHeader("token");

        return dbUserDetailService.findById(userId, request.getHeader(SystemConfig.TOKEN));
    }
}
